#!/usr/bin/env python3.12
# -*- coding: utf-8 -*-

import os

curpath = os.path.dirname(__file__)

if __name__ == "__main__":
    n = 3
    # *********************生成简答题数据**********************
    with open(curpath + "/jdt.txt", "r", encoding="utf-8") as f:
        jdts = f.read().split("\n\n")
    print((jdts[0].split("\n")))
    # print(jdts[0].split("\n")[0].split(".")[1])
    questionsData = {}
    for i in range(0, int(18 / n)):
        questions = []
        id = 1
        title = f"练习{i+1}"
        for j in range(i * n, (i + 1) * n):
            question = jdts[j].split("\n")[0].split(".")[1:]
            daan = "</p><p>".join(jdts[j].split("\n")[1:])
            questions.append(
                {
                    "id": id,
                    "question": question,
                    "answer": "</p><p>" + daan,
                }
            )
            # print(questions)
            id += 1
        questionsData[f"chapter{i+1}"] = {"title": title, "questions": questions}
    print("var questionsData = ", questionsData)
    with open("/dev/shm/jdt.js", "w", encoding="utf-8") as f:
        f.write("var questionsData = " + str(questionsData))

    n = 3
    # *********************生成论述题题数据**********************
    with open(curpath + "/lst.txt", "r", encoding="utf-8") as f:
        lsts = f.read().split("\n\n")

    questionsData = {}
    for i in range(0, int(12 / n)):
        questions = []
        id = 1
        title = f"练习{i+1}"
        for j in range(i * n, (i + 1) * n):
            question = lsts[j].split("\n")[0].split(".")[1:]
            daan = "</p><p>".join(lsts[j].split("\n")[1:])
            questions.append(
                {
                    "id": id,
                    "question": question,
                    "answer": "</p><p>" + daan,
                }
            )
            # print(questions)
            id += 1
        questionsData[f"chapter{i+1}"] = {"title": title, "questions": questions}
    print("var questionsData = ", questionsData)
    with open("/dev/shm/lst.js", "w", encoding="utf-8") as f:
        f.write("var questionsData = " + str(questionsData))
